package com.example.demo.controller;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

//@RestController
@RequestMapping("/return")
@Controller
public class ReturnController {


    @ResponseBody  //可修饰方法，可修饰类
    @RequestMapping("/indexData")
    public String indexData(){
        return "数据返回";
    }

    @ResponseBody
    @RequestMapping("/json")
    public Person returnjson() {
        Person person = new Person();
        person.setName("kzf");
        person.setAge(18);
        person.setHeight(185);
        return person;
    }

    @ResponseBody
    @RequestMapping("/map")
    public Map<String, String> returnMap() {
        Map<String, String> map = new HashMap<String, String>();
        map.put("name", "kzf");
        map.put("age", "18");
        map.put("height", "185");
        return map;
    }

    @ResponseBody
    @RequestMapping("/setStatus")
    public String setStatus(HttpServletResponse resp) {
        resp.setStatus(401);
        return "状态码设置成功";
    }

    @ResponseBody
    @RequestMapping(value = "/content-type",produces = "application/json;charset=utf-8")
    public String contentType() {
        return "{'ok':你好}";
    }

    @ResponseBody
    @RequestMapping("/setHeader")
    public String setHeader(HttpServletResponse resp) {
        resp.setHeader("myheader","zzz");
        return "set ok";
    }


}
